package com.woniuxy.mapper;

import com.woniuxy.model.dto.ChargingStatusDto;
import com.woniuxy.model.dto.FeeStandardDto;
import com.woniuxy.model.entity.ChargingRecords;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
* @author Administrator
* @description 针对表【charging_records】的数据库操作Mapper
* @createDate 2025-01-02 20:02:38
* @Entity com.woniuxy.model.entity.ChargingRecords
*/
public interface ChargingRecordsMapper extends BaseMapper<ChargingRecords> {



    /**
     * 根据订单号查询充电记录
     */
    ChargingRecords selectByOrderNumber(@Param("orderNumber") String orderNumber);





    @Select("SELECT electric_fee, service_fee, start_time, end_time " +
            "FROM station_fee_standard " +
            "WHERE station_id = #{stationId} " +
            "AND (start_time IS NULL AND end_time IS NULL OR " +
            "(start_time <= #{currentTime} AND end_time > #{currentTime})) " +
            "LIMIT 1")
    FeeStandardDto selectCurrentFeeStandard(@Param("stationId") Long stationId, @Param("currentTime") String currentTime);



    /**
     * 插入充电记录
     *
     * @param record 充电记录实体
     * @return 插入的行数
     */
    int insert(@Param("record") ChargingRecords record);


    /**
     * 根据 ID 更新电量和费用
     *
     * @param id                充电记录 ID
     * @param electricityQuantity 电量
     * @param amount            费用
     * @return 更新的行数
     */
    @Update("UPDATE charging_records " +
            "SET electricity_quantity = #{electricityQuantity}, " +
            "amount = #{amount} " +
            "WHERE id = #{id}")
    int updateElectricityAndAmountById(@Param("id") Long id,
                                       @Param("electricityQuantity") BigDecimal electricityQuantity,
                                       @Param("amount") BigDecimal amount);



    int updateRefundStatus(@Param("orderNumber") String orderNumber,
                           @Param("refundStatus") int refundStatus,
                           @Param("refundAmount") BigDecimal refundAmount,
                           @Param("refundTime") Date refundTime,
                           @Param("refundDescription") String refundDescription);

    @Select("SELECT * FROM charging_records " +
            "WHERE customer_id = #{customerId} AND refund_status > 0")
    List<ChargingRecords> getRefundOrdersByCustomerId(@Param("customerId") Long customerId);


}




